package com.chenfan.magic.config.aspect;
import com.chenfan.magic.constant.MagicConstant;
import com.chenfan.magic.service.proxy.DcControlExportTotalListProxy;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author liuming
 * @date 2021-06-04 15:42
 */
@Slf4j
@Aspect
@Component
public class HandleAspect {

    @Autowired
    private DcControlExportTotalListProxy dcControlExportTotalListProxy;

    @Pointcut("@annotation(com.chenfan.magic.annation.FetchHandle)")
    public void pointCut() {
    }

    @AfterReturning(pointcut = "pointCut()", returning = "keys")
    public void after(JoinPoint point, Object keys) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        if (request.getRequestURI().contains(MagicConstant.EXPORT_TITAL_LIST_PATH)) {
            dcControlExportTotalListProxy.handle(keys);
        }

    }

}
